<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
$return['basic']=$basic;
//我的关注
if($_RQ['op']=='main'){
	$list=pdo_getall('jy_xiaoeknow_userlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'isfollow'=>1,'mid'=>$_SESSION['uid']),'','createtime desc');
	if($list){
		foreach($list as &$item){
			$item['member']=pdo_get('core_members',array('id'=>$item['userid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','groupid','avatar','nickname'));
			$item['user']=pdo_get('jy_xiaoeknow_user',array('mid'=>$item['userid'],'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']));
			$item['fansnums']=pdo_count('jy_xiaoeknow_userlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'isfollow'=>1,'mid'=>$item['userid']));
		}
	}
	
	$return['list']=$list;
	$return['msgnum']=count($list);
	exi($return);

}
//我的粉丝
if($_RQ['op']=='fans'){
	
	$list=pdo_getall('jy_xiaoeknow_userlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'isfollow'=>1,'userid'=>$_SESSION['uid']),'','createtime desc');
	if($list){
		foreach($list as &$item){
			$item['member']=pdo_get('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','groupid','avatar','nickname'));
			$item['user']=pdo_get('jy_xiaoeknow_user',array('mid'=>$item['mid'],'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid']));
			$item['fansnums']=pdo_count('jy_xiaoeknow_userlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'isfollow'=>1,'mid'=>$item['userid']));
			$item['isfollowtoo']=pdo_getcolumn('jy_xiaoeknow_userlog',array('mid'=>$_SESSION['uid'],'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'userid'=>$item['mid']),'isfollow');
		}
	}
	$return['fansnum']=count($list);
	$return['list']=$list;
	exi($return);

}
if($_RQ['op']=='follow'){
	$postdata=get_postdata();
	$mid = intval($postdata['mid']);
	if($mid ==$_SESSION['uid']){
		exi('自己不能关注自己！','error');
	}
	$follow=pdo_get('jy_xiaoeknow_userlog',array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid'],'userid'=>$mid));
	if($follow){
			pdo_update('jy_xiaoeknow_userlog',array('isfollow'=>1,'createtime'=>TIMESTAMP),array('uniacid'=>$_SESSION['uniacid'],'merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid'],'userid'=>$mid));
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'merchid'=>$_SESSION['onemerchid'],
			'userid'=>$mid,
			'mid'=>$_SESSION['uid'],
			'isfollow'=>1,
			'createtime'=>TIMESTAMP
		);
		pdo_insert('jy_xiaoeknow_userlog',$insert);
	}
	exi('关注成功');
}